#parse argument

architecture=$1
matrix_decompressed_file=$2
matrix_comp_file=$3
output_dir=$4
lorem_ipsum_file=$5

permutation_str=""


# generate keys and hash

str="
xrnlib-cli \
    --encoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture $permutation_str \
    --make-monomial-key -monomial-key $output_dir/monomial_key_file.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture $permutation_str \
    --make-start-point -start-point $output_dir/start_point_file.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -start-point $output_dir/start_point_file.xf -monomial-key $output_dir/monomial_key_file.xf \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture \
    --make-binomial-key -binomial-key $output_dir/binomial_key_file.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture $permutation_str \
    --make-hash -plain-text $output_dir/monomial_key_file.xf -hash $output_dir/hash_file.xf
"
echo ""; echo $str; echo ""
eval $str

# convert binomial key to start point

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -binomial-key $output_dir/binomial_key_file.xf \
    --permutation-conf -arch $architecture \
    --convert-binomial-key-to-start-point -start-point $output_dir/start_point_file_1.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/start_point_file.json \
    --print-header -xrn-file $output_dir/start_point_file.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/start_point_file_1.json \
    --print-header -xrn-file $output_dir/start_point_file_1.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
cmp --silent $output_dir/start_point_file.json $output_dir/start_point_file_1.json || echo 'FAIL'
"
echo ""; echo $str; echo ""
eval $str

# convert start point to point and vice versa

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -start-point $output_dir/start_point_file_1.xf \
    --permutation-conf -arch $architecture \
    --convert-start-point-to-point -point $output_dir/point_file.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -point $output_dir/point_file.xf \
    --permutation-conf -arch $architecture \
    --convert-point-to-start-point -start-point $output_dir/start_point_file_2.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/start_point_file_2.json \
    --print-header -xrn-file $output_dir/start_point_file_2.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
cat $output_dir/start_point_file_1.json | grep start > $output_dir/start_point_file_1.stripped ; \
cat $output_dir/start_point_file_2.json | grep start > $output_dir/start_point_file_2.stripped ; \
cmp --silent $output_dir/start_point_file_1.stripped $output_dir/start_point_file_2.stripped || echo 'FAIL'
"
echo ""; echo $str; echo ""
eval $str

# convert monomial key to point and vice versa

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -point $output_dir/point_file.xf \
    --permutation-conf -arch $architecture \
    --convert-point-to-monomial-key -monomial-key $output_dir/monomial_key_file_1.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -monomial-key $output_dir/monomial_key_file_1.xf \
    --permutation-conf -arch $architecture \
    --convert-monomial-key-to-point -point $output_dir/point_file_1.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/point_file_1.json \
    --print-header -xrn-file $output_dir/point_file_1.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/point_file.json \
    --print-header -xrn-file $output_dir/point_file.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
cmp --silent $output_dir/point_file_1.json $output_dir/point_file.json || echo 'FAIL'
"
echo ""; echo $str; echo ""
eval $str

# convert monomial key to monomial commitment and vice versa

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -monomial-key $output_dir/monomial_key_file.xf \
    --permutation-conf -arch $architecture \
    --convert-monomial-key-to-monomial-commitment -monomial-commitment $output_dir/monomial_commitment_file.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -monomial-commitment $output_dir/monomial_commitment_file.xf \
    --permutation-conf -arch $architecture \
    --convert-monomial-commitment-to-monomial-key -monomial-key $output_dir/monomial_key_file_2.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/monomial_key_file_2.json \
    --print-header -xrn-file $output_dir/monomial_key_file_2.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/monomial_key_file.json \
    --print-header -xrn-file $output_dir/monomial_key_file.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
cmp --silent $output_dir/monomial_key_file_2.json $output_dir/monomial_key_file.json || echo 'FAIL'
"
echo ""; echo $str; echo ""
eval $str

#convert hash to point

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -hash $output_dir/hash_file.xf \
    --permutation-conf -arch $architecture \
    --convert-hash-to-point -point $output_dir/point_file_2.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
if [ ! -s $output_dir/point_file_2.xf ] ; then echo FAIL ; fi
"
echo ""; echo $str; echo ""
eval $str

#convert binomial key to asymmetric signature

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -binomial-key $output_dir/binomial_key_file.xf \
    --permutation-conf -arch $architecture \
    --convert-binomial-key-to-asymmetric-signature -asymmetric-signature $output_dir/asymmetric_signature.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -asy-signature $output_dir/asymmetric_signature.xf \
    --permutation-conf -arch $architecture \
    --convert-asymmetric-signature-to-binomial-key -binomial-key $output_dir/binomial_key_file2.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/binomial_key_file.json \
    --print-header -xrn-file $output_dir/binomial_key_file.xf
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/binomial_key_file2.json \
    --print-header -xrn-file $output_dir/binomial_key_file2.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
cmp --silent $output_dir/binomial_key_file2.json $output_dir/binomial_key_file.json || echo 'FAIL'
"
echo ""; echo $str; echo ""
eval $str

#convert binomial key to symmetric signature

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -binomial-key $output_dir/binomial_key_file.xf \
    --permutation-conf -arch $architecture \
    --convert-binomial-key-to-symmetric-signature -symmetric-signature $output_dir/symmetric_signature.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -sym-signature $output_dir/symmetric_signature.xf \
    --permutation-conf -arch $architecture \
    --convert-symmetric-signature-to-binomial-key -binomial-key $output_dir/binomial_key_file3.xf 
"
echo ""; echo $str; echo ""
eval $str

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/binomial_key_file3.json \
    --print-header -xrn-file $output_dir/binomial_key_file3.xf
"
echo ""; echo $str; echo ""
eval $str

str=" 
cmp --silent $output_dir/binomial_key_file3.json $output_dir/binomial_key_file.json || echo 'FAIL'
"
echo ""; echo $str; echo ""
eval $str
